namespace NBody.KD
{
    using System;
    using NBody;
    
    public abstract class Node
    {
        // total number of particles within node
        protected int n;
        // total mass
        protected double mass;
        // centre of mass coords
        protected double[] cm;
        // radius from centre of mass to furtherst corner
        protected double r_max;
        
        public int NumParts { get { return n; } }
        public double Mass { get { return mass; } }
        public double[] CentreOfMass { get { return cm; } }
        public double Rmax { get { return r_max; } }
        
        protected void ComputeRmax(double[,] bounds)
        {
            double[] dmax = {0,0,0};
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    double dist = Math.Abs(cm[j] - bounds[i,j]);
                    if (dist > dmax[j]) dmax[j] = dist;
                }
            }
            r_max = Math.Sqrt(dmax[0]*dmax[0] + dmax[1]*dmax[1] + dmax[2]*dmax[2]);
        }
        
        public abstract void FindNearest(double rd, ref SearchInfo info);
        
        public abstract void CalcPotential(IDParticle p, double theta, double eps, ref double phi);
    }
}
